package com.ma.serviceImp;

import com.ma.mapper.UserMapper;
import com.ma.model.User;
import com.ma.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    @Override
    public void create(String name, Integer age) {

    }

    @Override
    public void deleteByName(String name) {

    }

    @Override
    public Integer getAllUsers() {
        return null;
    }

    @Override
    public void deleteAllUsers() {

    }


    @Override
    public User findUserByPhone(String phone) {
        return userMapper.findUserByPhone(phone);
    }

    @Override
    public User findUserById(String id) {
        return null;
    }

    @Override
    public int insertUser(User user) {
        int flag = userMapper.insertUser(user);
        return flag;
    }

    @Override
    public void updatePasswordByPhone(String phone, String password) {
            userMapper.updatePasswordByPhone(phone, password);
    }

    @Override
    public void deleteUserByPhone(String phone) {
            userMapper.deleteUserByPhone(phone);
    }

    @Override
    public User findUserAndAdressByUser_id(String user_id) {
        return userMapper.findUserAndAdressByUser_id(user_id);
    }

    @Override
    public User findUserAndCarsById(int id) {
        return userMapper.findUserAndCarsById(id);
    }

    @Override
    public User findUserAndRoleByPhone(String phone) {
        return userMapper.getUserAndRolesByPhone(phone);
    }

    @Override
    public void updateRlByUsername(String recentLanded, String username) {
        userMapper.updateRlByUsername(recentLanded, username);
    }
//    @Autowired
//    private JdbcTemplate jdbcTemplate;
//
//    @Override
//    public void create(String name, Integer age) {
//        jdbcTemplate.update("insert into USER(NAME, AGE ) values(?, ?)", name, age);
//    }
//
//    @Override
//    public void deleteByName(String name) {
//        jdbcTemplate.update("delete from USER where NAME = ?", name);
//    }
//
//    @Override
//    public Integer getAllUsers() {
//        return jdbcTemplate.queryForObject("select count(1) from USER", Integer.class);
//    }
//
//    @Override
//    public void deleteAllUsers() {
//        jdbcTemplate.update("delete from USER");
//    }
}
